package com.llc.gulimall.order.web;

import com.alipay.api.AlipayApiException;
import com.llc.gulimall.order.config.AlipayTemplate;
import com.llc.gulimall.order.service.OrderService;
import com.llc.gulimall.order.vo.PayVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @author llc
 * @Description
 * @Version
 * @date 2022/3/1 19:58
 */
@Controller
public class payWebController {

    @Autowired
    OrderService orderService;

    @Autowired
    AlipayTemplate alipayTemplate;
    /**
     * 告诉浏览器，返回的字符串是text/html
     * @param orderSn
     * @return
     */
    @ResponseBody
    @GetMapping(value = "/payOrder", produces = "text/html;charset=UTF-8")
    public String pay(@RequestParam("orderSn") String orderSn) throws AlipayApiException {
        PayVo payVo = orderService.getOrderPay(orderSn);
        String pay = alipayTemplate.pay(payVo);
        //System.out.println(pay);
        return pay;
    }
}
